<template>
  <smart-page>
    <template #actions>
      <a-button v-auth="Acl.POP_ACTIVITY_MAIN_DELETE" :disabled="selectedKeys.length === 0" @click="onDelete()">批量删除</a-button>
      <a-button v-auth="Acl.POP_ACTIVITY_MAIN_ADD" type="primary" @click="editCtr.open()">新建注册活动</a-button>
    </template>
    <template #search>
      <smart-search :query-array="REGISTER_SEARCH" @on-handler="onSearch"/>
    </template>
    <a-table v-model:selectedKeys="selectedKeys"
             :table-layout-fixed="theme.layoutFixed"
             :row-selection="rowSelection"
             :columns="REGISTER_COLUMNS"
             :row-key="rowKey"
             :column-resizable="theme.resizable"
             :bordered="theme.bordered"
             :stripe="theme.stripe"
             :sticky-header="theme.sticky"
             :hoverable="theme.hoverAble"
             :pagination="pagination"
             :loading="theme.loading"
             :data="dataSource"
             @page-change="onPageChange"
             @page-size-change="onPageSizeChange">
      <template #action="{ record }">
        <a-space size="mini">
<!--          <a-link @click="toLink(record)">参与明细</a-link>-->
          <a-link v-auth="Acl.POP_ACTIVITY_MAIN_UPDATE" @click="editCtr.open(record)" >编辑</a-link>
          <a-link v-auth="Acl.POP_ACTIVITY_MAIN_DELETE" status="danger" @click="onDelete(record)"> 删除</a-link>
        </a-space>
      </template>
    </a-table>
    <edit-modal v-if="editCtr.show" :record="editCtr.record" @cancel="editCtr.close"/>

  </smart-page>
</template>
<script lang="ts" setup name="pop-activity-register">
import {onMounted} from 'vue';
import router from "@/libs/router";
import {REGISTER_SEARCH} from '../resource/search'
import {REGISTER_COLUMNS} from "../resource/colums";
import {TablePage} from "@/libs/core";
import {PopActivityHttp} from "../resource/http";
import EditModal from './edit.vue'
import {Acl} from "@/libs/acl";

const pageConfig = {title: '注册活动', rowKey: 'id', nameKey: 'title'}
const {getActivityPage, delActivity} = PopActivityHttp
const tablePage = new TablePage(pageConfig).setFetchXhr(getActivityPage).setDeleteXhr(delActivity).setPermission(Acl.POP_ACTIVITY_MAIN_PAGE_LIST);
const {theme, pagination, rowKey, dataSource, rowSelection, selectedKeys, editCtr} = tablePage
const {onFetch, onPageChange, onPageSizeChange, onDelete, onSearch} = tablePage
onMounted(() => onFetch())

const toLink = (record: { id: string }) => {
  router.push({
    path: '/pop/activity/attend',
    query: { activityId: record.id},
  })
}
</script>

